package cn.edu.web;

import cn.edu.pojo.*;
import cn.edu.service.TeacherService;
import cn.edu.service.dep_TeacherService;
import cn.edu.service.impl.TeacherServiceImpl;
import cn.edu.service.impl.dep_TeacherServiceImpl;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;

/**
 * @author Davey chan
 */
@WebServlet("/depTeacher/*")
public class dep_TeacherServlet extends BaseServlet {
    private dep_TeacherService tService = new dep_TeacherServiceImpl();


    //分页查询
    public void selectByPageAndCondition(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //        处理中文乱码
        request.setCharacterEncoding("utf-8");
//接受当前页码，和每页展示条数
        String _currentPage = request.getParameter("currentPage");
        String _pageSize = request.getParameter("pageSize");
//        String _academyName = request.getParameter("academyName");
//        byte[]  bytes = _academyName.getBytes("iso-8859-1");
//        String  academyName = new String(bytes,"utf-8");

        int currentPage = Integer.parseInt(_currentPage);
        int pageSize= Integer.parseInt(_pageSize);
//获取查询的封装对象

        BufferedReader br=request.getReader();
        String s = br.readLine();
        //        将JSON字符串转成JAVA对象
        All t = JSON.parseObject(s, All.class);
        PageBean<All> pageBean = tService.selectByPageAndcondition(currentPage, pageSize,t);


//将集合转换成JSON数据，也叫序列化
        String jsonString = JSON.toJSONString(pageBean);
//        响应数据
        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write(jsonString);
    }
    public void delteacher(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //接收页面返回的教师ID
        String _id = request.getParameter("id");
        int id = Integer.parseInt(_id);

        //        调用Service的同意
        tService.delteacher(id);
//        返回成功的标识
        response.getWriter().write("ok");
    }
    public void UpdateTeach_work(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //接收页面返回修改后的数据值
        //        处理中文乱码
        request.setCharacterEncoding("utf-8");
        BufferedReader br=request.getReader();
        String s = br.readLine();
        //        将JSON字符串转成JAVA对象
        teach_work t = JSON.parseObject(s, teach_work.class);
        //        调用Service的同意

        tService.Updateteach_work(t);
//        返回成功的标识
        response.getWriter().write("ok");
    }
    public void UpdateAnnual_examination(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //接收页面返回修改后的数据值
        //        处理中文乱码
        request.setCharacterEncoding("utf-8");
        BufferedReader br=request.getReader();
        String s = br.readLine();
        //        将JSON字符串转成JAVA对象
        annual_examination t = JSON.parseObject(s, annual_examination.class);
        //        调用Service的同意

        tService.UpdateAnnual_examination(t);
//        返回成功的标识
        response.getWriter().write("ok");
    }
    public void UpdatePatent(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //接收页面返回修改后的数据值
        //        处理中文乱码
        request.setCharacterEncoding("utf-8");
        BufferedReader br=request.getReader();
        String s = br.readLine();
        //        将JSON字符串转成JAVA对象
        patent t = JSON.parseObject(s, patent.class);
        //        调用Service的同意

        tService.UpdatePatent(t);
//        返回成功的标识
        response.getWriter().write("ok");
    }
    public void UpdateOpus(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //接收页面返回修改后的数据值
        //        处理中文乱码
        request.setCharacterEncoding("utf-8");
        BufferedReader br=request.getReader();
        String s = br.readLine();
        //        将JSON字符串转成JAVA对象
        opus t = JSON.parseObject(s, opus.class);
        //        调用Service的同意

        tService.UpdateOpus(t);
//        返回成功的标识
        response.getWriter().write("ok");
    }
    public void UpdateThesis(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //接收页面返回修改后的数据值
        //        处理中文乱码
        request.setCharacterEncoding("utf-8");
        BufferedReader br=request.getReader();
        String s = br.readLine();
        //        将JSON字符串转成JAVA对象
        thesis t = JSON.parseObject(s, thesis.class);
        //        调用Service的同意

        tService.UpdateThesis(t);
//        返回成功的标识
        response.getWriter().write("ok");
    }
    public void UpdateHonor(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //接收页面返回修改后的数据值
        //        处理中文乱码
        request.setCharacterEncoding("utf-8");
        BufferedReader br=request.getReader();
        String s = br.readLine();
        //        将JSON字符串转成JAVA对象
        honor_title t = JSON.parseObject(s, honor_title.class);
        //        调用Service的同意

        tService.UpdateHonor(t);
//        返回成功的标识
        response.getWriter().write("ok");
    }
    public void UpdateTrain(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //接收页面返回修改后的数据值
        //        处理中文乱码
        request.setCharacterEncoding("utf-8");
        BufferedReader br=request.getReader();
        String s = br.readLine();
        //        将JSON字符串转成JAVA对象
        train t = JSON.parseObject(s, train.class);
        //        调用Service的同意

        tService.UpdateTrain(t);
//        返回成功的标识
        response.getWriter().write("ok");
    }
    public void UpdateWork(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //接收页面返回修改后的数据值
        //        处理中文乱码
        request.setCharacterEncoding("utf-8");
        BufferedReader br=request.getReader();
        String s = br.readLine();
        //        将JSON字符串转成JAVA对象
        work t = JSON.parseObject(s, work.class);
        //        调用Service的同意

        tService.UpdateWork(t);
//        返回成功的标识
        response.getWriter().write("ok");
    }
    public void UpdateAward(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //接收页面返回修改后的数据值
        //        处理中文乱码
        request.setCharacterEncoding("utf-8");
        BufferedReader br=request.getReader();
        String s = br.readLine();
        //        将JSON字符串转成JAVA对象
        award t = JSON.parseObject(s, award.class);
        //        调用Service的同意

        tService.UpdateAward(t);
//        返回成功的标识
        response.getWriter().write("ok");
    }
    public void UpdateResearch_project(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //接收页面返回修改后的数据值
        //        处理中文乱码
        request.setCharacterEncoding("utf-8");
        BufferedReader br=request.getReader();
        String s = br.readLine();
        //        将JSON字符串转成JAVA对象
        research_project t = JSON.parseObject(s, research_project.class);
        //        调用Service的同意

        tService.UpdateResearch_project(t);
//        返回成功的标识
        response.getWriter().write("ok");
    }
}
